using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Xeml.Document;

namespace Xid.Controls
{
    public partial class AnnotationForm : Form
    {
        public AnnotationForm()
        {
            InitializeComponent();
            this.annotationCtrl.CloseMe += new EventHandler(annotationCtrl_CloseMe);
        }

        void annotationCtrl_CloseMe(object sender, EventArgs e)
        {
            if (annotationCtrl.AnnotationObject != null)
            {
                List<TaggedAnnotation> toRem = new List<TaggedAnnotation>();
                foreach (TaggedAnnotation ta in annotationCtrl.AnnotationObject.Annotations)
                {
                    if (string.IsNullOrEmpty(ta.Annotation))
                        toRem.Add(ta);
                }
                foreach (TaggedAnnotation ta in toRem)
                {
                    annotationCtrl.AnnotationObject.Annotations.Remove(ta);
                }
            }
            Close();
        }

        public void Setup(XemlAnnotatableObject xao)
        {
            this.annotationCtrl.AnnotationObject = xao;
        }

        public void Setup(XemlAnnotatableObject xao, string fixTag)
        {
            Setup(xao);
            annotationCtrl.FixTag = fixTag;
        }

    }
}